Generate input signals to support system identification

您所在的位置:网站首页 matlab input函数用法 Generate input signals to support system identification

Generate input signals to support system identification

2023-12-01 18:16| 来源: 网络整理| 查看: 265

Open Live Script

You can generate a sum-of-sinusoids signal using default characteristics for the sine waves. Alternatively, you configure the number of sine waves, and the frequencies and phases of the sine waves. This example shows both approaches.

Specify that the signal has 50 samples in each period and 3 periods. Also specify that the signal amplitude range is between -1 and 1.

Period = 50; NumPeriod = 3; Range = [-1 1];

Specify the frequency range of the signal. For a sum-of-sinusoids signal, you specify the lower and upper frequencies of the passband in fractions of the Nyquist frequency. In this example, use the entire frequency range between 0 and Nyquist frequency.

Band = [0 1];

First generate the signal using default characteristics for the sine waves. By default, the software uses 10 sine waves to generate the signal. The software assigns a random phase to each sinusoid, and then changes these phases 10 times to get the smallest signal spread. The signal spread is the difference between the minimum and the maximum value of the signal over all samples.

[u,freq] = idinput([Period 1 NumPeriod],'sine',Band,Range);

The software returns the sum-of-sinusoids signal in u and the frequencies of the sinusoids in freq. The values in freq are scaled assuming that the sample time is 1 time unit. Suppose that the sample time is 0.01 hours. To retrieve the actual frequencies in rad/hours, divide the values by the sample time.

Ts = 0.01; % Sample time in hours freq = freq/Ts; freq(1)ans = 12.5664

freq(1) is the frequency of the first sine wave. To see how the software chooses the frequencies, see the SineData argument description on the idinput reference page.

To verify that 10 sine waves were used to generate the signal, you can view the frequency content of the signal. Perform a Fourier transform of the signal, and plot the single-sided amplitude spectrum of the signal.

ufft = fft(u); Fs = 2*pi/Ts; % Sampling frequency in rad/hour L = length(u); w = (0:L-1)*Fs/L; stem(w(1:L/2),abs(ufft(1:L/2))) % Plot until Nyquist frequency title('Single-Sided Amplitude Spectrum of u(t)') xlabel('Frequency (rad/hour)') ylabel('Amplitude')

The generated plot shows the frequencies of the 10 sine waves used to generate the signal. For example, the plot shows that the first sine wave has a frequency of 12.57 rad/hour, the same as freq(1).

Convert the generated signal into an iddata object, and plot the signal. Specify the sample time as 0.01 hours.

u = iddata([],u,Ts,'TimeUnit','hours'); plot(u)

The signal u is generated using 10 sinusoids and has a period of 0.5 hours and 3 periods.

Now modify the number, frequency, and phase of the sinusoids that are used to generate the sum-of-sinusoids signal. Use 12 sinusoids and try 15 different sets of phases. To set the frequencies of the sinusoids, specify GridSkip = 2. The software selects the frequencies of the sinusoids from the intersection of the frequency grid 2*pi*[1:GridSkip:fix(Period/2)]/Period and the passband pi*Band.

NumSinusoids = 12; NumTrials = 15; GridSkip = 2; SineData = [NumSinusoids,NumTrials,GridSkip]; u2 = idinput([Period 1 NumPeriod],'sine',Band,Range,SineData);

Convert the generated signal into an iddata object, and plot the signal.

u2 = iddata([],u2,Ts,'TimeUnit','hours'); plot(u2)

The signal u2 is generated using 12 sinusoids and has a period of 0.5 hours and 3 periods.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3